import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";
import NotFound from "../views/404";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const routes = [
  {
    path: "/user",
    component: () => import(/* webpackChunkName: "user" */ "../layouts/UserLayout"),
    children: [
      {
        path: "/user/login",
        name: "login",
        component: () => import(/* webpackChunkName: "user" */ "../views/User/Login"),
      },
      {
        path: "/user/register",
        name: "register",
        component: () => import(/* webpackChunkName: "user" */ "../views/User/Register"),
      },
    ],
  },
  {
    path: "/dashboard",
    component: () => import(/* webpackChunkName: "layout" */ "../layouts/DashboardLayout"),
    children: [
      {
        path: "/dashboard/analysis",
        name: "analysis",
        component: () => import(/* webpackChunkName: "dashboard" */ "../views/Dashboard/Analysis"),
      },
    ],
  },
  {
    path: "/form",
    name: "form",
    component: () => import(/* webpackChunkName: "layout" */ "../layouts/FormLayout"),
    children: [
      {
        path: "/form/basic-form",
        name: "basicform",
        component: () => import(/* webpackChunkName: "form" */ "../views/Forms/BasicForm"),
      },
      {
        path: "/form/step-form",
        name: "stepform",
        component: () => import(/* webpackChunkName: "form" */ "../views/Forms/StepForm"),
        children: [
          {
            path: "/form/step-form/info",
            name: "info",
            component: () => import(/* webpackChunkName: "form" */ "../views/Forms/StepForm/StepInfo"),
          },
          {
            path: "/form/step-form/confirm",
            name: "confirm",
            component: () => import(/* webpackChunkName: "form" */ "../views/Forms/StepForm/StepConfirm"),
          },
          {
            path: "/form/step-form/result",
            name: "result",
            component: () => import(/* webpackChunkName: "form" */ "../views/Forms/StepForm/StepResult"),
          },
        ],
      },
    ],
  },
  {
    path: "/",
    name: "home",
    component: Home,
  },
  {
    path: "/*",
    name: "404",
    component: NotFound,
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

router.beforeEach((to, from, next) => {
  NProgress.start();
  next();
});

router.afterEach(() => {
  NProgress.done();
});

export default router;
